/**
 * @file Flash.c
 * @author SoBigDog (623644973lubin@163.com)
 * @brief 
 * @version 0.1
 * @date 2020-11-12
 * 
 * @copyright Copyright (c) 2020
 * 
 */
#include "Flash.h"

#define FLASH_START			0x0801F000
#define FLASH_SIZE			0x00001000

bool FlashInit(struct flash_area * pFlash)
{
	
}

bool flash_read(struct flash_area * pFlash, uint16_t offset, uint8_t * buff, uint32_t len)
{
	memcpy(buff, ((uint8_t)pFlash->m_addr) + offset, len);

	return true;
}

bool flash_write(struct flash_area * pFlash, uint16_t offset, uint8_t *, uint32_t)
{
	HAL_FLASH_Unlock();

	FLASH_EraseInitTypeDef f;
	f.TypeErase = FLASH_TYPEERASE_PAGES;
	f.PageAddress = addr;
	f.NbPages = 1;
	uint32_t PageError = 0;

	HAL_FLASHEx_Erase(&f, &PageError);

	HAL_FLASH_Program(TYPEPROGRAM_WORD, addr, writeFlashData);
	HAL_FLASH_Lock();
}

